/**
 * @function rest api基类
 * @author anytao
 * @created 2016-07-15
 * @version 1.0
 */
'use strict';

export default class extends think.controller.base  {

    /**
     * 基础验证
     */
    async __before(action) {
         
        //登录接口无需验证
        if (this.http.action === 'login') {
            return;
        }

        return;

        //获取http header token
        let userToken = this.http.header('token');

        //调用tokenService中间件
        let tokenService = think.service('token');
        let tokenServiceInstance = new tokenService();

        //验证token
        let verifyTokenResult = tokenServiceInstance.verifyToken(userToken);

        if (verifyTokenResult == 'fail') {
            return this.fail('TOKEN_INVALID');
        }

        //获取用户信息
        user = verifyTokenResult.userInfo;

        //写入新token
        let newToken = tokenServiceInstance.createToken(user);

        this.http.header('token', newToken);
    }
}